﻿using System.Configuration;
using System.Linq;

namespace AzureContrib.WindowsAzure.Tests.Utils
{
	/// <summary>
	/// A small helper that consults an app setting <see cref="UseFiddlerProxyConfigurationName"/> for wether to use Fiddler in the tests.
	/// </summary>
	public static class UseFiddlerHelper
	{
		/// <summary>
		/// Name of the app setting key that holds the <see cref="bool"/> value indicating wether to use Fiddler.
		/// </summary>
		public const string UseFiddlerProxyConfigurationName = "Use Fiddler Proxy For Windows Azure Storage Emulator";

		/// <summary>
		/// Do we use Fiddler in this test run?
		/// </summary>
		/// <remarks>Value is false if the app setting named <see cref="UseFiddlerProxyConfigurationName"/> is missing.</remarks>
		public static bool UseFiddler
		{
			get
			{
				if (!ConfigurationManager.AppSettings.AllKeys.Any(key => key == UseFiddlerProxyConfigurationName))
					return false;
				bool answer;
				return bool.TryParse(ConfigurationManager.AppSettings[UseFiddlerProxyConfigurationName], out answer) && answer;
			}
		}
	}
}